package atguigu;

import java.math.BigDecimal;
import java.text.DecimalFormat;

public class RateMain {

	private static DecimalFormat dformat = new DecimalFormat("0.00");
	
	public static void main(String[] args) {
		
		RateMain rateMain = new RateMain();
		
//		float rate = rateMain.getRate(4,52);
//		System.out.println(rate);
		
		Double absUseRate = rateMain.getAbsUseRate(2456, 5678,2);
		System.out.println(absUseRate);
	}
	
	
	public Double getAbsUseRate(double useHour,double natureHour,int scale){
        if(useHour == 0.0 || natureHour == 0.0) return 0.0;
        BigDecimal average = new BigDecimal( (double) useHour /natureHour * 100).setScale(scale, BigDecimal.ROUND_HALF_UP);
        double rate = average.doubleValue();
        if(rate>=100.00){
            rate = 100;
        }
        return rate;
    }
	
	float getRate(Integer a,Integer b){
        BigDecimal average = new BigDecimal( (float) a / b * 100).setScale(2, BigDecimal.ROUND_HALF_UP);
        return average.floatValue();
    }
	
	public Double getAbsUseRate(double useHour,double natureHour){
        if(useHour == 0.0 || natureHour == 0.0) return 0.0;
        BigDecimal average = new BigDecimal( (double) useHour /natureHour * 100).setScale(2, BigDecimal.ROUND_HALF_UP);
        double rate = average.doubleValue();
        if(rate>=100.00){
            rate = 100;
        }
        return rate;
    }
}
